<?php

    $projectnr = $_GET['project_nr'];
    $clientid  = $_GET['client_id'];

    $sql = "SELECT * FROM project p LEFT JOIN address a ON (a.address_id = p.address_id) WHERE p.project_nr = '" . $projectnr . "'";
    $result_p = mysql_query($sql);
    $sql = "SELECT * FROM client c LEFT JOIN address a ON (a.address_id = c.address_id) WHERE c.client_id = " . $clientid;
    $result_c = mysql_query($sql);

    if (mysql_num_rows($result_p) > 0 && mysql_num_rows($result_c) > 0) {
        $data_p = mysql_fetch_array($result_p);
        $data_c = mysql_fetch_array($result_c);

        if ($data_p['pm_id'] != 0) {
            $sql = "SELECT * FROM project_manager WHERE pm_id = " . $data_p['pm_id'];
            $result_pm = mysql_query($sql);
            $data_pm = mysql_fetch_array($result_pm);
        }

        if ($data_p['km_id'] != 0) {
            $sql = "SELECT * FROM project_manager WHERE pm_id = " . $data_p['km_id'];
            $result_km = mysql_query($sql);
            $data_km = mysql_fetch_array($result_km);
        }

?>
<ul class="ui-listview ui-listview-inset ui-corner-all ui-shadow" data-inset="true" data-role="listview">
    <li class="ui-li ui-li-static ui-body-c ui-corner-top">
        <table align="center">
            <tr>
                <td><h3 style="color:orange">Allgemein:</h3></td>
                <td></td>
            </tr>
            <tr>
                <td valign="top"><b>Projektname:</b></td>
                <td><?php echo $data_p['p_name']; ?></td>
            </tr>
            <tr height="5px"></tr>
            <tr>
                <td valign="top"><b>Anschrift:</b></td>
                <td>
                    <?php echo $data_p['street']; ?><br />
                    <?php echo $data_p['zip']; ?> <?php echo $data_p['city']; ?>
                </td>
            </tr>
            <tr height="5px"></tr>
            <tr>
                <td valign="top"><b>Projektnr.<br /><font style="color:#2666db"><?php echo $data_c['name']; ?>:</font></b></td>
                <td valign="bottom"><?php echo $data_p['project_nr_client']; ?></td>
            </tr>
            <tr height="3px"></tr>
            <tr>
                <td valign="top"><b>Bestellnr.<br /><font style="color:#2666db"><?php echo $data_c['name']; ?>:</font></b></td>
                <td valign="bottom"><?php echo $data_p['order_nr_client']; ?></td>
            </tr>
            <tr>
                <td><h3 style="color:orange">Auftraggeber:</h3></td>
                <td></td>
            </tr>
            <tr>
                <td><b>Name:</b></td>
                <td><?php echo $data_c['name']; ?></td>
            </tr>
            <tr height="5px"></tr>
            <tr>
                <td valign="top"><b>Anschrift:</b></td>
                <td>
                    <?php echo $data_c['street']; ?><br />
                    <?php echo $data_c['zip'] . ' ' . $data_c['city']; ?><br />
                </td>
            </tr>
            <tr>
                <td><h3 style="color:orange">Kaufmann:</h3></td>
                <td></td>
            </tr>
            <tr>
                <td><b>Name:</b></td>
                <td><?php echo $data_km['vorname'] . ' ' . $data_km['name']; ?></td>
            </tr>
            <tr>
                <td><b>Telefon:</b></td>
                <td><a href="tel:<?php echo $data_km['phone']; ?>"><?php echo $data_km['phone']; ?></a></td>
            </tr>
            <tr>
                <td><b>E-Mail:</b></td>
                <td><a href="mailto:<?php echo $data_km['email']; ?>"><?php echo $data_km['email']; ?></a></td>
            </tr>
            <tr>
                <td><b>Mobil:</b></td>
                <td><a href="tel:<?php echo $data_km['mobil']; ?>"><?php echo $data_km['mobil']; ?></a></td>
            </tr>
            <tr>
                <td><h3 style="color:orange">Projektleiter:</h3></td>
                <td></td>
            </tr>
            <tr>
                <td><b>Name:</b></td>
                <td><?php echo $data_pm['vorname'] . ' ' . $data_pm['name']; ?></td>
            </tr>
            <tr>
                <td><b>Telefon:</b></td>
                <td><a href="tel:<?php echo $data_pm['phone']; ?>"><?php echo $data_pm['phone']; ?></a></td>
            </tr>
            <tr>
                <td><b>E-Mail:</b></td>
                <td><a href="mailto:<?php echo $data_pm['email']; ?>"><?php echo $data_pm['email']; ?></a></td>
            </tr>
            <tr>
                <td><b>Mobil:</b></td>
                <td><a href="tel:<?php echo $data_pm['mobil']; ?>"><?php echo $data_pm['mobil']; ?></a></td>
            </tr>
            <tr>
                <td><h3 style="color:orange">Datum:</h3></td>
                <td></td>
            </tr>
            <tr>
                <td><b>Anfrage:</b></td>
                <td>
                    <?php
                        $datearray = explode('-', $data['date_inquiry']);
                        echo $datearray[2].'.'.$datearray[1].'.'.$datearray[0];
                    ?>
                </td>
            </tr>
            <tr>
                <td><b>Angebot:</b></td>
                <td>
                    <?php
                        $datearray = explode('-', $data['date_offer']);
                        echo $datearray[2].'.'.$datearray[1].'.'.$datearray[0];
                    ?>
                </td>
            </tr>
            <tr>
                <td><b>Bestellung:</b></td>
                <td>
                    <?php
                        $datearray = explode('-', $data['date_order']);
                        echo $datearray[2].'.'.$datearray[1].'.'.$datearray[0];
                    ?>
                </td>
            </tr>
            <tr>
                <td><h3 style="color:orange">Beträge:</h3></td>
                <td></td>
            </tr>
            <tr>
                <td><b>Angebot:</b></td>
                <td>
                   <?php
                        $money_of = $data_p['offer_sum'];
                        echo number_format($money_of, 2, ',', '.');
                   ?> &euro;
                </td>
            </tr>
            <tr>
                <td><b>Bestellung:</b></td>
                <td>
                    <?php
                        $money_or = $data_p['order_sum'];
                        echo number_format($money_or, 2, ',', '.');
                   ?> &euro;
                </td>
            </tr>
            <tr>
                <td><b>Differenz:</b></td>
                <td>
                    <?php
                        $money_dif = $money_or - $money_of;
                        if ($money_dif < 0) {
                            echo '<font style="color:red">' .number_format($money_dif, 2, ',', '.') . ' &euro;</font>';
                        } else {
                            echo '<font style="color:green">+' .number_format($money_dif, 2, ',', '.') . ' &euro;</font>';
                        }
                   ?>
                </td>
            </tr>
        </table>
    </li>
</ul>
<form action="php/stat_change.php" method="POST" data-ajax="false">
    <input type="hidden" name="projectnr" value="<?php echo $projectnr; ?>" />
    <h3 align="center">Bemerkung</h3>
    <textarea placeholder="Kommentar eintragen!" name="pcomment"><?php echo $data_p['comment']; ?></textarea>
    <h3 align="center">Projektstatus ändern</h3>
    <select name="status_choose" id="status_choose" data-native-menu="false">
        <option value="0">Noch offen</option>
        <option value="1">Auftrag</option>
        <option value="3" selected="true">Auftrag & Erledigt</option>
    </select>
    <br />
    <button type="submit" data-theme="e">Status ändern</button>
</form>
<?php
    }
?>